<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .commonHead{
      position: relative;
      z-index: 10;
    }
    .box{
      position: relative;
      z-index: 100;

      background-color: #fff;
    }
    #mask{
      position: fixed;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      background-color: rgba(0,0,0, .7);
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 1000;
    }
    .content{
      width: 40%;
      height: 40%;
      background-color: #fff;
    }
  </style>
</head>

<body>
  <div id="app">
    <div class="box">
      这是盒子内容
      <common-head></common-head>
    </div>
    
  </div>
  <script src="./vue.global.js"></script>
  <script src="./axios.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
    });
    const CommonHead = {
      template: `
        <div class="commonHead">
          <h2>这是组件1</h2>
          <button @click="showModal">显示弹窗</button>
          <Teleport to="body">
            <div id="mask" v-show="isShow" @click="hideModal">
              <div class="content" @click.stop>
                这是弹窗内容
              </div>
            </div>
          </Teleport>
        </div>
      `,
      data() {
        return {
         isShow: false
        }
      },
      methods: {
        hideModal(){
          this.isShow = false
        },
        showModal(){
          this.isShow = true
        }
      }
    }
    app.component('CommonHead', CommonHead)


    app.mount('#app')
  </script>
</body>

</html>